<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

require_once 'includes/connect.php';
require_once 'includes/function.php';

$db = new myDBS();

$i_date = $_REQUEST["i_date"];
$task = $_REQUEST["task"];
$account_no = $_REQUEST["account_no"];
$account_name = $_REQUEST["account_name"];

//$cheque_cancel_date = $_REQUEST["cheque_cancel_date"];
//$cheque_cancel_reason = $_REQUEST["cheque_cancel_reason"];
//
//$pause_status = $_REQUEST["pause_status"];
//
//$cheque_paid_date = $_REQUEST["cheque_paid_date"];
//$receiver_sign = $_REQUEST["receiver_sign"];

$branch_name = $_REQUEST["branch_name"];
$bank_name = $_REQUEST["bank_name"];
$bank_type = $_REQUEST["bank_type"];

$val = $_REQUEST["val"];

$val1 = explode(",", $val);
$val1 = implode("','", $val1);

//$tblname = $_REQUEST["tblname"];

switch ($task) {
    
    case "add":
        $sql = "UPDATE tbl_pet "
                . " SET account_no = '$account_no' "
                . " , account_name = '$account_name' "
                . " , branch_name = '$branch_name' "
                . " , bank_name = '$bank_name' "
                . " , bank_type = '$bank_type' "
                . " WHERE pet_id in('$val1')";
        
//        echo $sql;
        $db->runSQL($sql) or die(mysql_error());
        break;
    
    case "approvedCheque":

        $expire_date = strtotime("+45 days", strtotime($i_date));
        $expire_date = date("Y-m-d", $expire_date);
        
        $sql = "UPDATE tbl_pet "
                . " SET cheque_status = 'อนุมัติ' "
                . ", cheque_app_date = '$i_date' "
                . ", expire = '$expire_date' "
                . " WHERE cheque_no = '$cheque_no' ";

//        echo $sql;
        $db->runSQL($sql) or die(mysql_error());
        
        break;

    case "cheque_cancel":
        $sql = "UPDATE tbl_pet "
                . " SET cheque_status = 'ยกเลิก' "
                . ", cheque_cancel_reason = '$cheque_cancel_reason' "
                . ", cheque_cancel_date = '$cheque_cancel_date' "
                . " WHERE  cheque_no = '$cheque_no' ";
        //echo $sql;
        $db->runSQL($sql) or die(mysql_error());

        break;

    case "pause":
        $sql = "UPDATE tbl_pet "
                . " SET pause_status = '$pause_status' "
                . " WHERE  cheque_no = '$cheque_no' ";
        $db->runSQL($sql) or die(mysql_error());
        break;
    
    case "paid":
        
        $sql = "UPDATE tbl_pet "
                . " SET paid_status = 'จ่ายแล้ว'"
                . ", paid_date = '$cheque_paid_date'"
                . ", receiver_sign = '$receiver_sign' "
                . " WHERE  cheque_no = '$cheque_no' ";
        $db->runSQL($sql) or die(mysql_error());
        break;

    default:
        break;
}
?>

